//package com.neuedu.ec.common;
//
//import com.fasterxml.jackson.core.JsonGenerator;
//import com.fasterxml.jackson.core.JsonParser;
//import com.fasterxml.jackson.databind.DeserializationContext;
//import com.fasterxml.jackson.databind.JsonDeserializer;
//import com.fasterxml.jackson.databind.JsonSerializer;
//import com.fasterxml.jackson.databind.SerializerProvider;
//import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.io.IOException;
//import java.time.LocalDateTime;
//import java.time.ZoneOffset;
//import java.util.Date;
//
///**
// * jackson全局配置java8 LocalDateTime的序列化 全局配置时间返回格式
// */
//@Configuration
//public class JacksonCustomizerConfig {
//
//    /**
//     * description:适配自定义序列化和反序列化策略，返回前端指定数据类型的数据
//     */
//    @Bean
//    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
//        return builder -> {
//            builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer());
//            builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer());
//        };
//    }
//
//    /**
//     * description:序列化
//     * LocalDateTime序列化为毫秒级时间戳
//     */
//    public static class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
//        @Override
//        public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
//                throws IOException {
//            if (value != null) {
//                long timestamp = value.toEpochSecond(ZoneOffset.of("+8"));
//                gen.writeNumber(timestamp);
//            }
//        }
//    }
//
//    /**
//     * description:反序列化
//     * 毫秒级时间戳序列化为LocalDateTime
//     */
//    public static class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
//        @Override
//        public LocalDateTime deserialize(JsonParser p, DeserializationContext deserializationContext)
//                throws IOException {
//            long timestamp = p.getValueAsLong();
//            if (timestamp > 0) {
//                return new Date(timestamp).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();
//            } else {
//                return null;
//            }
//        }
//    }
//}